#!/bin/bash
make clean
NDK=/home/kevin/JYY/android/android-ndk-r21e
TOOLCHAIN=$NDK/toolchains/llvm/prebuilt/linux-x86_64
SYSROOT=$TOOLCHAIN/sysroot
API=21

function build_android
{
echo "Compiling FFmpeg for $CPU"
./configure \
    --prefix=$PREFIX \
    --disable-static \
    --disable-doc \
    --disable-ffmpeg \
    --disable-ffplay \
    --disable-ffprobe \
    --disable-doc \
    --disable-symver \
    --enable-nonfree \
    --enable-gpl \
    --enable-small \
    --enable-neon \
    --enable-hwaccels \
    --enable-avdevice \
    --enable-postproc \
    --enable-shared \
    --enable-jni \
    --enable-mediacodec \
    --enable-libx264 \
    --enable-libfdk-aac \
    --enable-decoder=h264_mediacodec \
    --cross-prefix=$CROSS_PREFIX \
    --target-os=android \
    --arch=$ARCH \
    --cpu=$CPU \
    --nm=$NM \
    --strip=$STRIP \
    --cc=$CC \
    --cxx=$CXX \
    --enable-cross-compile \
    --sysroot=$SYSROOT \
    --extra-cflags="-Os -fpic $OPTIMIZE_CFLAGS -I$FDK_AAC_INCLUDE -I$X264_INCLUDE" \
    --extra-ldflags="-L$FDK_AAC_LIBS -L$X264_LIBS $ADDI_LDFLAGS" \
    $ADDITIONAL_CONFIGURE_FLAG
make clean
make
make install
echo "The Compilation of FFmpeg for $CPU is completed"
}

#armv8-a
TARGET=aarch64-linux-android-
ARCH=aarch64 #arm64
VERSION=arm64
CPU=armv8-a
CROSS_PREFIX=$TOOLCHAIN/bin/${TARGET}
CC=$TOOLCHAIN/bin/aarch64-linux-android$API-clang
CXX=$TOOLCHAIN/bin/aarch64-linux-android$API-clang++
NM=$TOOLCHAIN/bin/${TARGET}nm
STRIP=$TOOLCHAIN/bin/${TARGET}strip
FDK_AAC_INCLUDE=/home/kevin/Kevin/Projects/JYY01/build/libfdk_aac/$CPU/include
X264_INCLUDE=/home/kevin/Kevin/Projects/JYY01/build/x264/$CPU/include
FDK_AAC_LIBS=/home/kevin/Kevin/Projects/JYY01/build/libfdk_aac/$CPU/lib
X264_LIBS=/home/kevin/Kevin/Projects/JYY01/build/x264/$CPU/lib
PREFIX=/home/kevin/Kevin/Projects/JYY01/build/ffmpeg445/$CPU
OPTIMIZE_CFLAGS="-mfloat-abi=softfp -mfpu=neon -marm"
build_android

#armv7-a
TARGET=arm-linux-androideabi-
ARCH=arm
VERSION=arm
CPU=armv7-a
CROSS_PREFIX=$TOOLCHAIN/bin/${TARGET}
CC=$TOOLCHAIN/bin/armv7a-linux-androideabi$API-clang
CXX=$TOOLCHAIN/bin/armv7a-linux-androideabi$API-clang++
NM=$TOOLCHAIN/bin/${TARGET}nm
STRIP=$TOOLCHAIN/bin/${TARGET}strip
FDK_AAC_INCLUDE=/home/kevin/Kevin/Projects/JYY01/build/libfdk_aac/$CPU/include
X264_INCLUDE=/home/kevin/Kevin/Projects/JYY01/build/x264/$CPU/include
FDK_AAC_LIBS=/home/kevin/Kevin/Projects/JYY01/build/libfdk_aac/$CPU/lib
X264_LIBS=/home/kevin/Kevin/Projects/JYY01/build/x264/$CPU/lib
PREFIX=/home/kevin/Kevin/Projects/JYY01/build/ffmpeg445/$CPU
OPTIMIZE_CFLAGS="-mfloat-abi=softfp -mfpu=neon"
build_android